<template>
	<view>
		<!-- 空白页 -->
		<u-empty v-if="isEmpty === true && followDataList.length === 0" :text="emptyText" mode="list"></u-empty>
		<goshop-merchant-display :data="followDataList"></goshop-merchant-display>
		<u-loadmore
				:status="loadStatus" 
				:loading-text="loadingText" 
				:loadmore-text="loadmoreText" 
				:nomore-text="nomoreText" 
				loadingIcon="semicircle"
				@loadmore="getGoodPage"
			/>
	</view>
</template>

<script>
	import {followPage} from '@/common/http.api.js'
	export default {
		data() {
			return {
				//加载更多标志
				loadMoreFlag:false,
				isEmpty:false,
				followDataList: [],
				emptyText:'',
				loadStatus: '',
				loadingText: '',
				loadmoreText: '',
				nomoreText: '',
				params: {
					pageNo: 1,
					status: 0, //全部
					pageSize: 10,
				},
			};
		},
		onReachBottom() {
			if(this.loadMoreFlag){
			  this.getFollowPage()
			}
		},
		onPullDownRefresh() {
			this.params.pageNo = 1
			this.followDataList = []
			this.getFollowPage()
		},
		onLoad(){
			this.getFollowPage()	
		},
		onShow(){
		  this.refresh();	
		},
		methods:{
			refresh(){
				this.emptyText = this.$t('common.empty.text');
				this.loadingText = this.$t('common.loading.text');
				this.loadmoreText = this.$t('common.loadmore.text');
				this.nomoreText = this.$t('common.nomore.text');
			},
			getFollowPage(){
				this.loadStatus = 'loading';
				followPage(this.params).then((res)=>{
					debugger
					uni.stopPullDownRefresh()
					if(res.code === 0){
					  if(res.data.list.length === 0){
						this.isEmpty = true;
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  }else if (res.data.list.length < 10) {
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  } else {
						this.params.pageNo++;
						this.loadStatus = 'loading'
						this.loadMoreFlag = true;
					  }
					  if (this.params.pageNo > 1) {
						this.followDataList = this.followDataList.concat(res.data.list);
					  } else {
						this.followDataList = res.data.list;
					  }
					}
				  }).catch(error=>{
					console.error(error)
				  })
			},
		}
	}
</script>

<style lang="scss">

</style>
